function doAjax_pro(arg) {
    return new Promise((resolve, reject) => {
        var {
            url,
            type = 'POST',
            data = {}
        } = arg;
        var obj = new XMLHttpRequest(); // XMLHttpRequest对象用于在后台与服务器交换数据
        obj.open(type, url);
        obj.onreadystatechange = function () {
            if (obj.readyState == 4 && obj.status == 200 || obj.status == 304) { // readyState == 4说明请求已完成
                console.log('promise resolve');
                resolve(obj)
            }
        };
        obj.send(data);
    })
}

function doAjax(params) {
      var {
            url,
            type = 'POST',
            data = {},
            success = null
        } = params;
        //默认参数

        var obj = new XMLHttpRequest(); // XMLHttpRequest对象用于在后台与服务器交换数据
        obj.open(type, url);
        obj.onreadystatechange = function () {
            if (obj.readyState == 4 && obj.status == 200 || obj.status == 304) { // readyState == 4说明请求已完成
                console.log('normal callback');
                success && success(obj)
            }
        };
        obj.send(data);
}

export { doAjax, doAjax_pro }